<%@page import="java.io.* , java.util.*, java.sql.*, com.myapp.struts.actionform.*, com.myapp.struts.dao.*, com.myapp.struts.beans.*"%>
<html>
    <head>
        <title>Supplier Master</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <link href="../../../../css/cms.css" rel="stylesheet" type="text/css">
        <script type="text/javascript">
            var st=0;
            function getXMLObject()  //XML OBJECT
            {
                var xmlHttp = false;
                try {
                    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
                }
                catch (e) {
                    try {
                        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
                    }
                    catch (e2) {
                        xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
                    }
                }
                if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
                    xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
                }
                return xmlHttp;  // Mandatory Statement returning the ajax object created
            }

            var xmlhttp = new getXMLObject();	//xmlhttp holds the ajax object

            function getDetails() {
                var sel = document.getElementById("supplierName");
                var opt = sel.options[sel.selectedIndex];
                var d = opt.value || opt.text;

                if(xmlhttp) {
                    xmlhttp.open("POST","../../../../AJAXSuppliers?supname=" +d,true);
                    xmlhttp.onreadystatechange  = handleServerResponse;
                    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                    xmlhttp.send(null);
                }
            }

            function handleServerResponse() {
                if (xmlhttp.readyState == 4) {
                    if(xmlhttp.status == 200) {
                        document.getElementById('add').value= 0;
                        document.getElementById('phone').value = 0;
                        document.getElementById('fax').value= 0;
                        document.getElementById('tandc').value= 0;
                        document.getElementById('pan').value = 0;
                        document.getElementById('staxnum').value= 0;
                        document.getElementById('staxtype').value= 0;
                        document.getElementById('ml').value = 0;
                        document.getElementById('loc').value= 0;
						                       
                        var textToSplit = xmlhttp.responseText;
                        var returnElements=textToSplit.split("|");
                        valueLabelPair = returnElements[1].split("|");
                        document.getElementById('add').value=valueLabelPair;
							
                        valueLabelPair = returnElements[2].split("|");
                        document.getElementById('phone').value =valueLabelPair;
							
                        valueLabelPair = returnElements[3].split("|");
                        document.getElementById('fax').value= valueLabelPair;
							
							
                        valueLabelPair = returnElements[8].split("|");
                        document.getElementById('tandc').value= valueLabelPair;
							
                        valueLabelPair = returnElements[4].split("|");
                        document.getElementById('pan').value= valueLabelPair;
							
                        valueLabelPair = returnElements[5].split("|");
							
                        document.getElementById('staxnum').value= valueLabelPair;
                        valueLabelPair = returnElements[6].split("|");
							
                        document.getElementById('staxtype').value= valueLabelPair;
							
                        valueLabelPair = returnElements[7].split("|");
                        document.getElementById('ml').value= valueLabelPair;
							
                        valueLabelPair = returnElements[9].split("|");
                        document.getElementById('loc').value= valueLabelPair;
							
							
                        
                    }else {
                        alert("Error during AJAX call. Please try again");
                    }
                }
            }
            function Validate()
			{
			var index1=document.supplier.supplierName.selectedIndex;                        
                        if(index1<=0)
                        {
                            alert("Please Select Supplier Name....");                            
                            document.supplier.supplierName.focus();
                            return false;
                        }
			}
        </script>
    </head>
    <body>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">

            <tr>
                <td height="570" align="center" valign="top">
                    <form id="supplier" name="supplier" action="../../../../EditSupplier" onSubmit="return Validate();">
                        <table width="100%" height="272" border="0" align="center" cellpadding="0" cellspacing="0"  class="subHeader" style="border-right: #000000 1px solid;
                               border-top: #000000 1px solid; border-left: #000000 1px solid;  border-bottom: #000000 1px solid; font-size: 9pt; color: #000000; font-family: Arial;">
              <tr>
                                <th height="26" colspan="2">Supplier Master</th>
                          </tr>
                            <tr>
                                <td width="490" align="left" valign="middle" >Supplier Name </td>
                          <td width="486" valign="top">
                  <select name="supplierName" id="supplierName" onChange="javascript:getDetails()">
                                        <option> </option>
                                        <%
                                                        SupplierDao sdao=new SupplierDao();
                                                        Vector gp1 = sdao.getSupplierNames();
                                if (gp1 != null) {
                                    Iterator itg = gp1.iterator();
                                    while (itg.hasNext()) {
                                        SupplierMasterFormBean gb = (SupplierMasterFormBean) itg.next();
                                        String supp_name = gb.getSupplierName();
                                        %>
                                        <option value="<%=supp_name%>"><%=supp_name%></option>
                                        <%}

                                }%>
                                    </select>            </td>
                          </tr>
                            <tr>
                                <td align="left" valign="middle">Address</td>
                                <td valign="top">
                                    <input name="add" type="text" id="add" />            </td>
                            </tr>
                            <tr>
                                <td align="left" valign="middle">Phone Number</td>
                                <td valign="top"><input name="phone" type="text" id="phone" /></td>
                            </tr>
                            <tr>
                                <td align="left" valign="middle">Fax Number</td>
                                <td valign="top"><input name="fax" type="text" id="fax" value="0" /></td>
                            </tr>
                            <tr>
                                <td height="22" align="left" valign="middle" >Terms and Conditions</td>
                                <td valign="top">
                                    <input name="tandc" type="text" id="tandc" />            </td>
                            </tr>
                            <tr>
                                <td align="left">PAN Number</td>
                                <td valign="top"><input name="pan" type="text" id="pan" value="  " /></td>
                            </tr>
                            <tr>
                                <td align="left">Sales Tax Number</td>
                                <td valign="top"><input name="staxnum" type="text" id="staxnum" value="  " /></td>
                            </tr>
                            <tr>
                                <td align="left">Sales Tax Type</td>
                                <td valign="top"><input name="staxtype" type="text" id="staxtype" value="   " /></td>
                            </tr>
                            <tr>
                                <td align="left">Monitory Limit</td>
                                <td valign="top"><input name="ml" type="text" id="ml" value="0" /></td>
                            </tr>
                            <tr>
                                <td align="left">Location</td>
                                <td valign="top"><input type="text" name="loc" id="loc"></td>
                            </tr>
                            <tr>
                                <td height="24" colspan="2" align="center"><input name="Submit" type="submit" value="Submit" /></td>
                          </tr>
                        </table>
                  </form>      </td>
            </tr>
        </table>
    </body>
</html>
